<template>
  <view class="num_box">
    <view class="num_box_btn num_box_minus" @tap.stop="minus(value, step, minValue)"
      >-</view
    >
    <view class="num_box_value">{{ value || 0 }}</view>
    <view class="num_box_btn num_box_plus" @tap.stop="plus(value, step, maxValue)">
      +
    </view>
  </view>
</template>

<script>
export default {
  name: 'u-number-box',
  props: {
    step: {
      type: Number,
      default: 1,
    },
    maxValue: {
      type: Number,
      default: null,
    },
    minValue: {
      type: Number,
      default: null,
    },
    value: {
      type: Number,
      default: 0,
    }
  },
  data() {
    return {
      
    };
  },
  watch: {},
  created() {},
  methods: {
    minus(value, step, minValue) {
      if (minValue !== null && this.value - step < minValue) return;
      value -= step;
      this.$emit('changeNumber', value)
    },
    plus(value, step, maxValue) {
      if (maxValue !== null && this.value + step > maxValue) return;
      value += step;
      this.$emit('changeNumber', value)
    },
  },
};
</script>
<style lang="less">
.num_box {
  display: flex;
  align-items: center;
  .num_box_btn {
    width: 50rpx;
    height: 50rpx;
    border-radius: 50%;
    border: 2rpx solid #ffd7b6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40rpx;
    color: #ffd7b6;
  }
  .num_box_plus {
    background-color: #ffd7b6;
    color: #fff;
  }
  .num_box_value {
    font-size: 28rpx;
    font-family: PingFangSC-Semibold;
    font-weight: 600;
    white-space: nowrap;
    line-height: 40rpx;
    margin: 0 20rpx 0 16rpx;
  }
}
</style>
